package com.ruoyi.training.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.training.dto.BatchCheckStatusDto;
import com.ruoyi.training.dto.CheckInQueryDto;
import com.ruoyi.training.vo.CheckInVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.training.domain.PracticeCheckIn;
import com.ruoyi.training.service.IPracticeCheckInService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 实践预约签到Controller
 *
 * @author WorrilessGo
 * @date 2025-10-14
 */
@RestController
@RequestMapping("/practiceCheckIn")
public class PracticeCheckInController extends BaseController
{
    @Autowired
    private IPracticeCheckInService practiceCheckInService;

    /**
     * 查询实践预约签到列表
     */
    @RequiresPermissions("training:practiceCheckIn:list")
    @GetMapping("/list")
    public TableDataInfo list(PracticeCheckIn practiceCheckIn)
    {
        startPage();
        List<PracticeCheckIn> list = practiceCheckInService.selectPracticeCheckInList(practiceCheckIn);
        return getDataTable(list);
    }

    /**
     * 通过条件搜索查询实践预约签到列表
     * lqx
     */

    @GetMapping("/search")
    public TableDataInfo searchCheckIn(CheckInQueryDto checkInQueryDto)
    {
        startPage();
        List<CheckInVO> list = practiceCheckInService.searchCheckIn(checkInQueryDto);
        return getDataTable(list);
    }

    /**
     * 导出实践预约签到列表
     */
    @RequiresPermissions("training:practiceCheckIn:export")
    @Log(title = "实践预约签到", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PracticeCheckIn practiceCheckIn)
    {
        List<PracticeCheckIn> list = practiceCheckInService.selectPracticeCheckInList(practiceCheckIn);
        ExcelUtil<PracticeCheckIn> util = new ExcelUtil<PracticeCheckIn>(PracticeCheckIn.class);
        util.exportExcel(response, list, "实践预约签到数据");
    }

    /**
     * 获取实践预约签到详细信息
     */
    @RequiresPermissions("training:practiceCheckIn:query")
    @GetMapping(value = "/{practiceCheckId}")
    public AjaxResult getInfo(@PathVariable("practiceCheckId") String practiceCheckId)
    {
        return success(practiceCheckInService.selectPracticeCheckInByPracticeCheckId(practiceCheckId));
    }

    /**
     * 新增实践预约签到
     */
    @RequiresPermissions("training:practiceCheckIn:add")
    @Log(title = "实践预约签到", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PracticeCheckIn practiceCheckIn)
    {
        return toAjax(practiceCheckInService.insertPracticeCheckIn(practiceCheckIn));
    }

    /**
     * 修改实践预约签到
     */
    @RequiresPermissions("training:practiceCheckIn:edit")
    @Log(title = "实践预约签到", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PracticeCheckIn practiceCheckIn)
    {
        return toAjax(practiceCheckInService.updatePracticeCheckIn(practiceCheckIn));
    }

    /**
 * 批量修改签到状态
 * lqx
 */
@PostMapping("/batchUpdateStatus")
public AjaxResult batchUpdateStatus(@RequestBody BatchCheckStatusDto batchCheckStatusDto)
{
    return toAjax(practiceCheckInService.batchUpdateStatus(batchCheckStatusDto));
}

    /**
     * 删除实践预约签到
     */
    @RequiresPermissions("training:practiceCheckIn:remove")
    @Log(title = "实践预约签到", businessType = BusinessType.DELETE)
	@DeleteMapping("/{practiceCheckIds}")
    public AjaxResult remove(@PathVariable String[] practiceCheckIds)
    {
        return toAjax(practiceCheckInService.deletePracticeCheckInByPracticeCheckIds(practiceCheckIds));
    }
}
